package org.biloxi.model.card.impl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.biloxi.card.Card;
import org.biloxi.model.card.CardInstance;
import org.biloxi.player.PlayerID;

public class CardInstanceImpl implements CardInstance {
	private final Card 	   	  _card;
	private 	  PlayerID 	  _controller;
	private final PlayerID 	  _owner;
	private final Set<String> _subTypes = new HashSet<String>();
	
	private 	  Card.Type   _type;
	
	/**
	 * Creates a CardInstance based on it's {@link Card} specification.
	 * @param c Card that specifies this CardInstance
	 */
	CardInstanceImpl(Card c, PlayerID owner) { 
		_card = c;
		_owner = owner;
		_type = Card.Type.Spell;
		_subTypes.addAll(Arrays.asList(_card.getSubTypes()));
	}
	
	public Card getCard(){ 
		return _card;
	}

	public PlayerID getController() {
		return _controller;
	}

	public PlayerID getOwner() {
		return _owner;
	}
	
	public String[] getSubTypes() {
		return _subTypes.toArray(new String[0]);
	}

	public Card.Type getType() {
		return _type;
	}

	public boolean is(Card.Type type){
		return _type == type;
	}
	public boolean is(String subType){
		return _subTypes.contains(subType);
	}
	
	public void setController(PlayerID _controller) {
		this._controller = _controller;
	}

	public void setType(Card.Type _type) {
		this._type = _type;
	}
	
}
